package com.k.configcenter.nacos.test;

import java.io.IOException;
import java.io.StringReader;
import java.util.Properties;
import java.util.stream.Collectors;

/**
 * Created by 170623910 on 2021/10/27.
 */
public class PropertiesEx extends Properties {
    private static final String DELIMITER_EQUALS="=";
    private static final String DELIMITER_LINE=System.lineSeparator();
    public static Properties load(String propertiesString) throws IOException {
        Properties properties = new Properties();
        if(propertiesString != null){
            properties.load(new StringReader(propertiesString));
        }
        return properties;
    }
    public static String formatString(Properties properties){
        return properties.entrySet().stream().map(a->a.getKey() + DELIMITER_EQUALS + a.getValue()).collect(Collectors.joining(DELIMITER_LINE));
    }
}